#include "../include/TcpClientSocket.hpp"

TcpClientSock::TcpClientSock(const char* p_ip,int p_port)
{
    bzero(&m_clientSockAddr,sizeof(m_clientSockAddr));
    m_clientSockAddr.sin_family = AF_INET;
    m_clientSockAddr.sin_port = htons(p_port);
    inet_pton(AF_INET,p_ip,&m_clientSockAddr.sin_addr);
    m_sockfd = socket(AF_INET,SOCK_STREAM,0);
    assert(m_sockfd != -1);
    printf("build socket fd success  = [%d]\n",m_sockfd);
    m_clientStop = false;
}

TcpClientSock::~TcpClientSock()
{
    close(m_sockfd);
}

void TcpClientSock::ConnectSock()
{
    int ret = connect(m_sockfd,(sockaddr*)&m_clientSockAddr,sizeof(m_clientSockAddr));
    assert(ret != -1);
    printf("connect success\n");
}

void TcpClientSock::MessageLoop()
{
    while(!m_clientStop)
    {
        Update();
    }
}
